package model.interactionHandlerInitializer;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import controller.GameConfig;
import model.entity.Mountable;
import model.entity.MountableNPC;
import model.interactionhandler.InteractionContainer;
import model.interactionhandler.MountHandler;
import model.interactionhandler.PickPocketHandler;
import model.map.World;
import model.resource.AvatarMount;


public class MountHandlerInitializer extends InteractionHandlerInitializer{
	
	KeyListener keyListener;
	
	public MountHandlerInitializer(String theName) {
		super(theName);
	}

	public void handle(){
		final MountHandler mh = new MountHandler("MountHandler");
		MountableNPC mountable = ((MountableNPC)InteractionContainer.getInstance().getTarget());
		mh.mount(InteractionContainer.getInstance().getAvatar(), mountable);
		
		// adding controller
		GameConfig.GAME_WINDOW.addKeyListener(new KeyListener() {

			@Override
			public void keyPressed(KeyEvent arg0) {
				if( arg0.getKeyCode() == GameConfig.EXIT_INTERACTION && 
						AvatarMount.getInstance().isMounted(World.getInstance().getPlayer())) {
					mh.unmount(World.getInstance().getPlayer(), 
							AvatarMount.getInstance().getMount(World.getInstance().getPlayer()));
				}
			}

			@Override
			public void keyReleased(KeyEvent arg0) {
//				if( arg0.getKeyCode() == GameConfig.EXIT_INTERACTION && 
//						InteractionContainer.getInstance().isInteracting()) {
//					mh.unmount(World.getInstance().getPlayer(), 
//							AvatarMount.getInstance().getMount(World.getInstance().getPlayer()));
//				}
			}

			@Override
			public void keyTyped(KeyEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
		});
	}
}